#clean up
rm(list=ls())

#required libraries
library(lme4)
library(foreign)

#load data
####Be sure to use setwd() to set your working directory to the location of the following file.####
####Also, read.dta() is for the Stata version of the file.####
smoking<-read.dta("tvsfp.dta")

#Three-Level Model (students within classes within schools)
smoking.mod<-lmer(post~pre+schT+tvT+schT*tvT+(1|schoolID)+(1|classID), data=smoking)
summary(smoking.mod)

#Ignoring the Clustered Nature of the Data
naive.mod<-lm(post~pre+schT+tvT+schT*tvT, data=smoking)
summary(naive.mod)
